home *** CD-ROM | disk | FTP | other *** search
- #include <string.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <limits.h>
-
- #include "DeskLib:WimpSWIs.h"
- #include "DeskLib:Font.h"
- #include "DeskLib:GFX.h"
-
- #include "Shell.FontLabel.h"
- #include "Shell.Extra.h"
- #include "Shell.SafeAlloc.h"
-
-
-
-
- typedef struct {
- char *text;
- int yoffset;
- int forecol, backcol;
- }
- fontlabel_ref;
-
-
-
- #define fontplot_JUSTIFY 0x00000001
- #define fontplot_RUBOUT 0x00000002
- #define fontplot_ABSCOORS 0x00000004
- #define fontplot_OSCOORS 0x00000010
-
-
-
- static char Shell_fontname[ 256] = "Trinity.Medium";
- static font_handle handle = NULL;
- static int Shell_Fxsize = 16*14, Shell_Fysize = 16*14;
- static font_info Shell_fontinfo;
-
-
-
- #define Shell_EnsureHandle() \
- if ( !handle) { \
- Font_FindFont( &handle, Shell_fontname, Shell_Fxsize, Shell_Fysize, 0, 0); \
- Font_ReadInfo( handle, &Shell_fontinfo); \
- } \
-
-
-
-
- static void Shell_KillHandle()
- {
- Font_LoseFont( handle);
- handle = NULL;
- }
-
-
-
-
- static int Shell_GetXSizeOfFontString( const char *s)
- { font_string fontstring;
- int xbox, dummy;
-
- fontstring.s = (char *) s;
- fontstring.x = INT_MAX; /* available x-space */
- fontstring.y = INT_MAX; /* available y-space */
- fontstring.split = -1; /* don't look for places to split text */
- fontstring.term = strlen( s); /* number of chrs to look at */
- Font_StringWidth( &fontstring); /* .x is width of string in font coors */
- Font_ConvertToOS( fontstring.x, 0, &xbox, &dummy);
- return xbox;
- }
-
-
-
-
-
-
-
- static void Shell_FontLabelDisplayer(
- Shell_convertpoint convert,
- wimp_point rectsize,
- void *reference,
- const wimp_rect *redrawrect
- )
-
- { fontlabel_ref *info = (fontlabel_ref *) reference;
- int screenx, screeny;
- UNUSED( redrawrect);
-
- Shell_EnsureHandle();
- Font_SetFont( handle);
-
- if ( info->forecol < 8 && info->backcol < 8 )
- Font_SetFontColours( handle, info->backcol, info->backcol, info->forecol - info->backcol);
- else Font_SetFontColours( handle, info->backcol, info->forecol, 0);
-
- Shell_Move( 0, 0, convert);
- Shell_Move( rectsize.x, rectsize.y, convert);
-
- screenx = Shell_ConvertXToScreen( 0, convert);
- screeny = Shell_ConvertYToScreen( info->yoffset, convert);
-
- Font_Paint( info->text, fontplot_RUBOUT | fontplot_OSCOORS, screenx, screeny);
-
- Shell_KillHandle();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- Shell_rectblock *Shell_FontLabel(
- Shell_windblock *w,
- int x, int y,
- int forecol, int backcol,
- const char *text
- )
-
- { wimp_rect rect;
- int len = strlen( text);
- fontlabel_ref *textinfo = Shell_SafeMalloc( sizeof( fontlabel_ref));
-
- Shell_EnsureHandle();
-
- rect.min.x = x;
- rect.max.x = x + Shell_GetXSizeOfFontString( text);
- rect.max.y = y+Shell_fontinfo.maxy;
- rect.min.y = y+Shell_fontinfo.miny;
-
- textinfo->text = Shell_SafeMalloc( 1+len);
- strcpy( textinfo->text, text);
-
- textinfo->yoffset = -Shell_fontinfo.miny;
-
- textinfo->forecol = forecol;
- textinfo->backcol = backcol;
-
- {
- Shell_rectblock *r;
- r = Shell_AddRectangle( w, &rect, Shell_FontLabelDisplayer, (void *) textinfo);
- Shell_MakeRectIcon( r, forecol, backcol, "R1");
- return r;
- }
- }
-
-
-
-
-
- Shell_rectblock *Shell_FontLabelf(
- Shell_windblock *w,
- int x, int y,
- int forecol, int backcol,
- const char *fmt, ...
- )
- {
- va_list args;
-
- va_start( args, fmt);
- vsprintf( Shell_string, fmt, args);
- va_end( args);
-
- return Shell_FontLabel( w, x, y, forecol, backcol, Shell_string);
-
- }
-
-
-
-